package github.kawaiior.yuanchuxiuzhen.common.item.misc;

import github.kawaiior.yuanchuxiuzhen.core.init.itemgroup.YcxzGroup;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Food;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;

import javax.annotation.Nullable;
import java.util.List;

public class HerbItem extends Item {

    private static final Food food = (new Food.Builder())
            .saturation(1)  // 饱腹度
            .hunger(1) // 鸡腿
            .setAlwaysEdible().build();

    private final int level;
    private final int id;

    public HerbItem(int level, int id) {
        super(new Properties().group(YcxzGroup.YCXZ_GROUP).food(food));
        this.level = level;
        this.id = id;
    }

    private void onUsed(PlayerEntity player, World world){
        // 或许可以加点效果?
    }

    @Override
    public ItemStack onItemUseFinish(ItemStack stack, World world, LivingEntity entityLiving) {
        if (entityLiving instanceof PlayerEntity && !entityLiving.world.isRemote){
            onUsed((PlayerEntity) entityLiving, world);
        }
        return super.onItemUseFinish(stack, world, entityLiving);
    }

    public int getLevel() {
        return level;
    }

    public int getId() {
        return id;
    }

    @Override
    public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
        tooltip.add(new TranslationTextComponent("item.yuanchuxiuzhen.herb.level."+this.level));
        tooltip.add(new TranslationTextComponent("item.yuanchuxiuzhen.herb.desc."+this.id));
    }
}
